﻿#include<iostream>
#include<stdexcept>


struct LinkedList {
	LinkedList* next;
	int val;

	LinkedList(int x) :val(x), next(nullptr) {
	}
	//插入节点，在node节点后插入新节点
	void Insert(LinkedList* node, LinkedList* p) {
		//获得当前节点的next节点
		LinkedList* next = node->next;
		//将当前节点的next节点指向新节点
		node->next = p;
		//将新节点的next节点指向原来的next节点
		p->next = next;
	}
	//删除节点，在node节点后删除节点
	void Delete(LinkedList* node) {
		if (node->next == nullptr)
			return;
		LinkedList* delNode = node->next;
		LinkedList* nextNode = delNode->next;
		node->next = nextNode;
		//释放内存
		delete delNode;
	}
	//访问节点，访问第n个节点，时间复杂度O(n)
	LinkedList* Get(LinkedList* head, int index) {
		if (head == nullptr)
			throw std::out_of_range("linkedlist is empty");
		for (int i = 0; i < index; i++) {
			head = head -> next;
		}
		return head;
	}
	//查找节点，也是访问节点的一种
	int find(LinkedList* head, int findValue) {
		int index = 0;
		while (head!=nullptr) {
			if (head->val == findValue)
				return index;
			head = head->next;
			index++;
		};
		return -1;
	}
};

int main() {

	LinkedList* no1 = new LinkedList(1);
	LinkedList* no2 = new LinkedList(2);
	no1->next = no2;

	std::cin.get();
}